#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@File ：ProductController.py
@Author ：zqy
@Email : zqingy@work@163.com 
@note: 
"""

from flask_restx import Namespace, Resource

from application.Parser.ProductParser import ProductValidator
from application.controller import register_crud_model
from application.logic.ProductLogic import ProductLogic
from application.util.ResponseUtil import ResponseUtil

product_ns = Namespace('product', description='商品模块')

product_parser: ProductValidator = ProductValidator

register_crud_model(
    ns=product_ns,
    logic_cls=ProductLogic,
    parser=product_parser,
    roles=["superuser"],
    route="",
    id_type="int",
    include_operations=["get","list", "put", "post"]
)


@product_ns.route("/<int:_id>/shelf")
class ProductUp(Resource):
    p = product_parser.shelf()

    @product_ns.expect(p)
    def put(self, _id):
        """上下架商品"""
        return ResponseUtil(data=ProductLogic.update_by_id(_id, self.p.parse_args())).success()
